# coding=utf-8
from worldcup.apps.userModel.models import Game
from worldcup.commons.CommonResult import rest, CommonResult


@rest
def list_game(request):
    games = Game.objects.all()
    result = []
    for game in games:
        result.append({
            "id": game.id,
            "homeTeam": game.home_team,
            "awayTeam": game.away_team,
			"matchName": "match" + str(game.id) + "(" + game.home_team + " vs " + game.away_team + ")"
        })
    return CommonResult(0, result)


@rest
def get_game(request):
    id = request.GET["id"]
    game = Game.objects.filter(id=id).get()
    return CommonResult(0, {
        "id": game.id,
        "homeTeam": game.home_team,
        "awayTeam": game.away_team,
		"matchName": "match" + str(game.id) + "(" + game.home_team + " vs " + game.away_team + ")"
    })


@rest
def list_team(request):
    result = []
    games = Game.objects.values("home_team").filter(type="小组赛").distinct().all()
    for game in games:
        result.append(game["home_team"])
    return CommonResult(0, result)
